home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / packet / p_aa4re / bb212src / bboinit.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-01-12  |  12.4 KB  |  408 lines

  1. (*===========================================================================*)
  2. (* Procedure for initializing option file                                    *)
  3. (*                                                                           *)
  4. (*   Copyright 1988, 1989, 1991 by H. Roy Engehausen.  All rights reserved.  *)
  5. (*                                                                           *)
  6. (*===========================================================================*)
  7.  
  8. {$UNDEF  DEBUG_OPT1}  (* Port semaphore numbers *)
  9. {$UNDEF  DEBUG_OPT2}  (* Track progress *)
  10.  
  11. PROCEDURE option_init;
  12.  
  13.   {$I BBOTYPE.PAS}
  14.  
  15.   VAR
  16.     c_list_size : WORD;
  17.     i           : BYTE;
  18.     in_file     : file_name_str;
  19.     j           : WORD;
  20.     last_port   : port_block_ptr;
  21.     look_port   : port_block_ptr;
  22.     opt_buffer  : ^opt_file_rec;
  23.     opt_file    : FILE OF opt_file_rec;
  24.     scb         : str_chain_ptr;
  25.     sema_num    : BYTE;
  26.     this_fd     : fsb_ptr;
  27.  
  28.   BEGIN;
  29.  
  30.     {$IFDEF DEBUG_OPT2}
  31.       WRITELN('Start option load');
  32.       DELAY(300);
  33.     {$ENDIF}
  34.  
  35.     in_file := PARAMSTR(1);
  36.  
  37.     IF in_file = '' THEN
  38.       in_file := 'BBOPT.BB';
  39.  
  40.     {$IFDEF DEBUG_OPT2}
  41.       WRITELN('Assign option');
  42.       DELAY(300);
  43.     {$ENDIF}
  44.  
  45.     ASSIGN(opt_file, in_file);
  46.  
  47.     {$IFDEF DEBUG_OPT2}
  48.       WRITELN('Open option');
  49.       DELAY(300);
  50.     {$ENDIF}
  51.  
  52.     {$I-}
  53.     RESET(opt_file);
  54.     {$I+}
  55.     IF IORESULT <> 0 THEN
  56.       BEGIN;
  57.         WRITELN(' ');
  58.         WRITELN('Can''t open ', in_file, '.  Has BBSETUP been run OK?');
  59.         WRITELN('You must have successfully run BBSETUP to create the');
  60.         WRITELN(in_file);
  61.         WRITELN(' ');
  62.         HALT;
  63.       END;
  64.  
  65.     (*-----------------------------------------------------------------------*)
  66.     (* Allocate buffer                                                       *)
  67.     (*-----------------------------------------------------------------------*)
  68.  
  69.     {$IFDEF DEBUG_OPT2}
  70.       WRITELN('Allocate buffer');
  71.       DELAY(300);
  72.     {$ENDIF}
  73.  
  74.  
  75.     NEW(opt_buffer);
  76.  
  77.     (*-----------------------------------------------------------------------*)
  78.     (* Read option block                                                     *)
  79.     (*-----------------------------------------------------------------------*)
  80.  
  81.     {$IFDEF DEBUG_OPT2}
  82.       WRITELN('Read main block');
  83.       DELAY(300);
  84.     {$ENDIF}
  85.  
  86.     READ(opt_file, opt_buffer^);
  87.     opt_block := opt_buffer^.opt_block_file;
  88.  
  89.     (*-----------------------------------------------------------------------*)
  90.     (* Verify option block                                                   *)
  91.     (*-----------------------------------------------------------------------*)
  92.  
  93.     {$IFDEF DEBUG_OPT2}
  94.       WRITELN('Verify main block');
  95.       DELAY(300);
  96.     {$ENDIF}
  97.  
  98.     WITH opt_block DO
  99.       IF parm_file_ver <> this_bbs_parms THEN
  100.         BEGIN;
  101.           WRITELN;
  102.           WRITELN('Incorrect version of the PARMS.BB has been found.');
  103.           WRITELN('Expected ', this_bbs_parms,
  104.                   ' but got ', parm_file_ver, '.');
  105.        WRITELN('Rerun the proper version of BBSETUP that matches this program');
  106.           WRITELN;
  107.           WRITELN;
  108.           HALT;
  109.         END;
  110.  
  111.     (*-----------------------------------------------------------------------*)
  112.     (* Read port blocks                                                      *)
  113.     (*-----------------------------------------------------------------------*)
  114.  
  115.     {$IFDEF DEBUG_OPT2}
  116.       WRITELN('Start port loop');
  117.       DELAY(300);
  118.     {$ENDIF}
  119.  
  120.     ring_port := NIL;
  121.  
  122.     sema_num := semaphore_port_start;
  123.  
  124.     i := opt_block.port_count;
  125.  
  126.     WHILE i > 0 DO
  127.       BEGIN;
  128.  
  129.         (*-------------------------------------------------------------------*)
  130.         (* Read a block                                                      *)
  131.         (*-------------------------------------------------------------------*)
  132.  
  133.         {$IFDEF DEBUG_OPT2}
  134.           WRITELN('Read port blk');
  135.           DELAY(300);
  136.         {$ENDIF}
  137.  
  138.         DEC(i);
  139.  
  140.         READ(opt_file, opt_buffer^);
  141.  
  142.         (*-------------------------------------------------------------------*)
  143.         (* Allocate space and copy it over                                   *)
  144.         (*-------------------------------------------------------------------*)
  145.  
  146.         {$IFDEF DEBUG_OPT2}
  147.           WRITELN('Allocate port');
  148.           DELAY(300);
  149.         {$ENDIF}
  150.  
  151.         NEW(active_port);
  152.  
  153.         active_port^ := opt_buffer^.opt_port_file;
  154.  
  155.         (*-------------------------------------------------------------------*)
  156.         (* Chain the port in                                                 *)
  157.         (*-------------------------------------------------------------------*)
  158.  
  159.         {$IFDEF DEBUG_OPT2}
  160.           WRITELN('Chain port');
  161.           DELAY(300);
  162.         {$ENDIF}
  163.  
  164.         IF ring_port = NIL THEN
  165.           ring_port := active_port
  166.         ELSE
  167.           last_port^.next_port := active_port;
  168.  
  169.         last_port := active_port;
  170.  
  171.         (*-------------------------------------------------------------------*)
  172.         (* Set the main port                                                 *)
  173.         (*-------------------------------------------------------------------*)
  174.  
  175.         {$IFDEF DEBUG_OPT2}
  176.           WRITELN('Main port');
  177.           DELAY(300);
  178.         {$ENDIF}
  179.  
  180.         active_port^.main_port := active_port;
  181.         active_port^.next_port := NIL;
  182.         active_port^.rel_port  := NIL;
  183.  
  184.         (*-------------------------------------------------------------------*)
  185.         (* See if this is a PCPA or BPQ subport.  If so, connect things      *)
  186.         (* together                                                          *)
  187.         (*-------------------------------------------------------------------*)
  188.  
  189.         WITH active_port^ DO
  190.           IF (port_type = port_pcpa) OR (port_type = port_bpqhost) THEN
  191.             BEGIN;
  192.  
  193.               {$IFDEF DEBUG_OPT2}
  194.                 WRITELN('PCPA/BPQ port');
  195.                 DELAY(300);
  196.               {$ENDIF}
  197.  
  198.               look_port := ring_port;
  199.  
  200.               WHILE (look_port <> NIL) AND (look_port <> active_port) DO
  201.                 IF look_port^.com_number = com_number THEN
  202.                   BEGIN;
  203.                     port_sub_port       := TRUE;
  204.                     main_port           := look_port^.main_port;
  205.                     rel_port            := look_port^.rel_port;
  206.                     look_port^.rel_port := active_port;
  207.                     connected           := look_port^.connected;
  208.                     look_port           := NIL;
  209.  
  210.                   END
  211.                 ELSE
  212.                   look_port := look_port^.next_port;
  213.  
  214.             END;
  215.  
  216.         (*-------------------------------------------------------------------*)
  217.         (* Allocate the connected array.  If a sub port, use the master      *)
  218.         (*-------------------------------------------------------------------*)
  219.  
  220.         {$IFDEF DEBUG_OPT2}
  221.           WRITELN('Connected array');
  222.           DELAY(300);
  223.         {$ENDIF}
  224.  
  225.         WITH active_port^ DO
  226.           IF NOT port_sub_port THEN
  227.             BEGIN;
  228.               c_list_size := (max_chan + 2) * SIZEOF(active_tcb);
  229.               GETMEM(connected, c_list_size);
  230.               FILLCHAR(connected^, c_list_size, #0);
  231.             END
  232.           ELSE
  233.             connected := main_port^.connected;
  234.  
  235.         (*-------------------------------------------------------------------*)
  236.         (* Assign a semaphore number to it.  If sub-port, use the master     *)
  237.         (*-------------------------------------------------------------------*)
  238.  
  239.         {$IFDEF DEBUG_OPT2}
  240.           WRITELN('Semaphore number');
  241.           DELAY(300);
  242.         {$ENDIF}
  243.  
  244.         WITH active_port^ DO
  245.           IF port_sub_port THEN
  246.             port_sema := main_port^.port_sema
  247.           ELSE
  248.             BEGIN;
  249.               IF port_sema = 0 THEN
  250.                 BEGIN;
  251.                   port_sema := sema_num;
  252.                   INC(sema_num);
  253.                 END
  254.               ELSE
  255.             END;
  256.  
  257.         {$IFDEF DEBUG_OPT2}
  258.           WRITELN('Port define -- ', active_port^.port_char,
  259.                   ' -- ', active_port^.port_num,
  260.                   ' -- ', active_port^.port_sub_port);
  261.           DELAY(1000);
  262.         {$ENDIF}
  263.  
  264.       END; (*----- End port read loop ---------------------------------------*)
  265.  
  266.     (*-----------------------------------------------------------------------*)
  267.     (* Save highest semaphore number                                         *)
  268.     (*-----------------------------------------------------------------------*)
  269.  
  270.     high_semaphore := sema_num - 1;
  271.  
  272.     (*-----------------------------------------------------------------------*)
  273.     (* Now complete the chain to give us a loop                              *)
  274.     (*-----------------------------------------------------------------------*)
  275.  
  276.     last_port^.next_port := ring_port;
  277.  
  278.     (*-------------------------------------------------------------------------*)
  279.     (* Create dummy port for the operator/forward tcbs                         *)
  280.     (*-------------------------------------------------------------------------*)
  281.  
  282.     {$IFDEF DEBUG_OPT2}
  283.       WRITELN('dummy port');
  284.       DELAY(300);
  285.     {$ENDIF}
  286.  
  287.     FILLCHAR(dummy_port, SIZEOF(dummy_port), #0);
  288.  
  289.     WITH dummy_port DO
  290.       BEGIN;
  291.         next_port  := NIL;
  292.         main_port  := @dummy_port;
  293.         rel_port   := NIL;
  294.         port_type  := port_console;
  295.         com_number := 0;
  296.         port_char  := 'L';
  297.         max_pac    := 80;
  298.         data_rate  := 0;
  299.         max_conn   := 1;
  300.         max_chan   := 2;
  301.         port_pend  := 100;
  302.         call_set   := '';
  303.         port_color := default_data_color;
  304.         c_list_size := (max_chan + 2) * SIZEOF(active_tcb);
  305.         GETMEM(connected, c_list_size);
  306.         FILLCHAR(connected^, c_list_size, #0);
  307.       END;
  308.  
  309.     (*-----------------------------------------------------------------------*)
  310.     (* Initialize the watch blocks                                           *)
  311.     (*-----------------------------------------------------------------------*)
  312.  
  313.     {$IFDEF DEBUG_OPT2}
  314.       WRITELN('Watch block dummy');
  315.       DELAY(300);
  316.     {$ENDIF}
  317.  
  318.     j := opt_block.n_mon * SIZEOF(port_call_item);
  319.  
  320.     IF j = 0 THEN
  321.       j := SIZEOF(port_call_item);
  322.  
  323.     WITH dummy_port DO
  324.       BEGIN;
  325.         GETMEM(call_list, j);
  326.         FILLCHAR(call_list^, j, CHR(0));
  327.       END;
  328.  
  329.     active_port := ring_port;
  330.  
  331.     REPEAT
  332.  
  333.       {$IFDEF DEBUG_OPT2}
  334.         WRITELN('Watch block loop');
  335.         DELAY(300);
  336.       {$ENDIF}
  337.  
  338.       WITH active_port^ DO
  339.         BEGIN;
  340.           GETMEM(call_list, j);
  341.           FILLCHAR(call_list^, j, CHR(0));
  342.           active_port := next_port;
  343.         END;
  344.  
  345.     UNTIL active_port = ring_port;
  346.  
  347.     (*-----------------------------------------------------------------------*)
  348.     (* Read file block                                                       *)
  349.     (*-----------------------------------------------------------------------*)
  350.  
  351.     {$IFDEF DEBUG_OPT2}
  352.       WRITELN('File blocks');
  353.       DELAY(300);
  354.     {$ENDIF}
  355.  
  356.     i        := opt_block.fd_count;
  357.     fsb_base := NIL;
  358.  
  359.     WHILE i > 0 DO
  360.       BEGIN;
  361.  
  362.         {$IFDEF DEBUG_OPT2}
  363.           WRITELN('File block loop');
  364.           DELAY(300);
  365.         {$ENDIF}
  366.  
  367.         DEC(i);
  368.  
  369.         READ(opt_file, opt_buffer^);
  370.  
  371.         NEW(this_fd);
  372.  
  373.         this_fd^ := opt_buffer^.opt_fd_file;
  374.  
  375.         this_fd^.next_fsb := fsb_base;
  376.         fsb_base          := this_fd
  377.  
  378.       END;
  379.  
  380.     (*-----------------------------------------------------------------------*)
  381.     (* Done with options file                                                *)
  382.     (*-----------------------------------------------------------------------*)
  383.  
  384.     {$IFDEF DEBUG_OPT2}
  385.       WRITELN('Close option');
  386.       DELAY(300);
  387.     {$ENDIF}
  388.  
  389.     CLOSE(opt_file);
  390.  
  391.     (*-----------------------------------------------------------------------*)
  392.     (* Drop buffer                                                           *)
  393.     (*-----------------------------------------------------------------------*)
  394.  
  395.     {$IFDEF DEBUG_OPT2}
  396.       WRITELN('Drop buffer');
  397.       DELAY(300);
  398.     {$ENDIF}
  399.  
  400.     DISPOSE(opt_buffer);
  401.  
  402.     {$IFDEF DEBUG_OPT2}
  403.       WRITELN('Option done');
  404.       DELAY(300);
  405.     {$ENDIF}
  406.  
  407.   END;
  408.